$(function(){
    var detailUrl = "/json/productManage.productDetail";
    var id = $.util.getRequest("id");
    $.ajax({
        url: $.util.getRequestJson(detailUrl),
        type: 'GET',
        data:{id:id},
        dataType: 'JSON',
        success: function(res) {
            // 弹窗展示数据
            if (res.success) {
                res.data.isDiscount = res.data.isDiscount == 1 ? '是' : '否';
                res.data.discountPrice = res.data.discountPrice == null ? '无' : res.data.discountPrice;
                res.data.discountScore = res.data.discountScore == null ? '无' : res.data.discountScore;
                res.data.isQuality = res.data.isQuality == 1 ? '是' : '否';
                res.data.isHome = res.data.isHome == 1 ? '是' : '否';
                res.data.realName = res.data.realName == null ? '无' : res.data.realName;
                res.data.name = res.data.name == null ? '---' : res.data.name;
                res.data.detail = res.data.detail.trim() == "" ? '无' : res.data.detail;
                res.data.verifyExplain = res.data.verifyExplain == null ? '无' : res.data.verifyExplain;
                if( res.data.status == 1){
                    res.data.status = '已上架';
                }else if(res.data.status == 2){
                    res.data.status = '已下架';
                }else{
                    res.data.status = '待上架';
                }
                if( res.data.verifyResult == 0){
                    res.data.verifyResult = '未通过';
                }else if(res.data.verifyResult == 1){
                    res.data.verifyResult = '已通过';
                }else{
                    res.data.verifyResult = '待审核';
                }
                $('#productDetail').form('load', res.data);

                if (res.data.attachedFile) {
                    if ($.util.isString(res.data.attachedFile)) {
                        res.data.attachedFile = JSON.parse(res.data.attachedFile);
                    }
                    var attachments= $('#attachments').html('');
                    for (var i = 0; i < res.data.attachedFile.length; i++) {
                        var file = res.data.attachedFile[i];
                        var el = $('<div style="padding-top: 5px;float: left;margin-left: 5px"><a target="_blank" href="' + $.util.getRootPath() + file.savePath + '">' + '<img src="'+$.util.getRootPath() + file.savePath+'" style="width: 50px;height: 50px;">' + '</a></div>');
                        attachments.append(el);
                    }
                }

                if (res.data.attachedFileQuality) {
                    if ($.util.isString(res.data.attachedFileQuality)) {
                        res.data.attachedFileQuality = JSON.parse(res.data.attachedFileQuality);
                    }
                    var attachmentsQuality= $('#attachmentsQuality').html('');
                    if(res.data.attachedFileQuality.length < 1){
                        var ell = $('<div style="padding-top: 5px;float: left;margin-left: 1px">无</div>');
                        attachmentsQuality.append(ell);
                    }else{
                        for (var j = 0; j < res.data.attachedFileQuality.length; j++) {
                            var filee = res.data.attachedFileQuality[j];
                            var elll = $('<div style="padding-top: 5px;float: left;margin-left: 5px"><a target="_blank" href="' + $.util.getRootPath() + filee.savePath + '">' + '<img src="'+$.util.getRootPath() + filee.savePath+'" style="width: 50px;height: 50px;">' + '</a></div>');
                            attachmentsQuality.append(elll);
                        }
                    }
                }
            }
        }
    });
})
